import axios from 'axios';

import { ElMention, ElMessage } from 'element-plus';

//const baseURL = 'http://localhost';
const baseURL = '/api';
const instance = axios.create({baseURL})



instance.interceptors.response.use(
    result=>{
        //判断业务状态码
        if(result.data.code===0){
            return result.data;
        }

        //操作失败
        ElMessage.error(result.data.msg?result.data.msg:'服务异常');
        
        //将异步操作的状态转换为失败
        return Promise.reject(result.data)
    },
    err=>{
        ElMessage.error('服务异常');
        return Promise.reject(err);
    }
)


export default instance;